import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        token : "", // 登录token

        step:0,//第几步

        AH: "",//案号

        submitData: {},//要提交的数据,

        LABD:"",//立案标的

        ygList: [], //原告
        bgList:[] , //被告

        trialExtraId: 0,

        trialExtraType:""
    },
    mutations: {
        SET_TRIAL_EXTRA_TYPE(state,data){
          state.trialExtraType = data;
        },

        SET_TRIAL_EXTRA_ID(state,data){
            state.trialExtraId = data;
        },
        SET_YGLIST(state, data) {
            state.ygList = data
        },

        SET_BGLIST(state, data) {
            state.bgList = data
        },

        SET_LABD(state, data) {
            state.LABD = data;
        },

        SET_SUBMIT_DATA(state, data) {
            state.submitData = data;
        },

        SET_AH(state, data) {
            state.AH = data;
        },

        SET_TOKEN(state, data) {
            state.token = data;
        },

        RESET_DATA(state) {
            state.token = "";
            state.step = 0;
            state.AH = "";
            state.submitData = {};
            state.LABD = "";
            state.trialExtraId = 0;
        },

        SET_STEP(state, data) {
            state.step = data;
        },


    },
    actions: {

        setTrialExtraType({ commit },data){
            commit('SET_TRIAL_EXTRA_TYPE',data)
        },


        setTrialExtraId({ commit },data){
            commit('SET_TRIAL_EXTRA_ID',data)
        },

        setLABD({commit}, data) {
            commit('SET_LABD',data)
        },

        setSubmitData({commit},data) {
            commit('SET_SUBMIT_DATA',data)
        },

        getToken({commit}) {
            let token = this.state.token;
            if (token === "") {
                token = window.sessionStorage.getItem('token');
                commit('SET_TOKEN', token);
            }
            return token
        },

        setToken({commit}, data) {
            commit('SET_TOKEN', data);
            window.sessionStorage.setItem('token', data);
         },

        resetToken({ commit }){

            commit('RESET_DATA');
            window.sessionStorage.setItem('token', "");
            window.sessionStorage.setItem('step', 0);
            window.sessionStorage.setItem('AH','')
        },

        clearSessionStorage({commit}){
            window.sessionStorage.setItem('token', "");
            window.sessionStorage.setItem('step', 0);
            window.sessionStorage.setItem('AH','')
        },



        setAH({commit}, data) {
            commit('SET_AH',data)
            window.sessionStorage.setItem('AH',data)
        },

        setStep({commit},data) {
            commit('SET_STEP', data);
            window.sessionStorage.setItem('step', data);
        },

        setBgList({commit}, data) {
            commit('SET_BGLIST', data);
        },

        setYgList({commit}, data) {
            commit('SET_YGLIST',data)
        }

    },

})